#include<bits/stdc++.h>
#define ONLINE_JUDGE
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 2e5 + 10, INF = 0x3f3f3f3f;

int n, q;
int f[N];
vector<int> s[N];

int find(int x) { return x != f[x] ? f[x] = find(f[x]) : f[x]; }
void merge(int x, int y) {
    int fx = find(x), fy = find(y);
    if (fx == fy) return;
    for (int v : s[fy]) s[fx].push_back(v);
    sort(s[fx].begin(), s[fx].end(), greater<int>());
    if (s[fx].size() > 10) s[fx].erase(s[fx].begin() + 10, s[fx].end());
    f[fy] = fx;
}

void solve()
{
    int op, x, y;
    cin >> n >> q;
    for (int i = 1;i <= n;i++) {
        s[i].push_back(i);
        f[i] = i;
    }

    while (q--) {
        cin >> op >> x >> y;
        if (op == 1) merge(x, y);
        else {
            int fx = find(x);
            if (s[fx].size() < y)
                cout << -1 << '\n';
            else cout << s[fx][y - 1] << '\n';
        }
    }
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}